var Animation = class {
constructor(file, width, height, speed) {
this.actor = new St.Bin();
+ this.actor.set_size(width, height);
this.actor.connect('destroy', this._onDestroy.bind(this));
+ this.actor.connect('notify::size', this._syncAnimationSize.bind(this));
+ this.actor.connect('resource-scale-changed',
+ this._loadFile.bind(this, file, width, height));
+
this._speed = speed;
this._isLoaded = false;
this._timeoutId = 0;
this._frame = 0;
- let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
- this._animations = St.TextureCache.get_default().load_sliced_image (file, width, height, scaleFactor,
- this._animationsLoaded.bind(this));
- this.actor.set_child(this._animations);
+ this._loadFile(file, width, height);
}
play() {
this._isPlaying = false;
}
+ _loadFile(file, width, height) {
+ let [validResourceScale, resourceScale] = this.actor.get_resource_scale();
+
+ this._isLoaded = false;
+ this.actor.destroy_all_children();
+
+ if (!validResourceScale)
+ return;
+
+ let texture_cache = St.TextureCache.get_default();
+ let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
+ this._animations = texture_cache.load_sliced_image(file, width, height,
+ scaleFactor, resourceScale,
+ this._animationsLoaded.bind(this));
+ this.actor.set_child(this._animations);
+ }
+
_showFrame(frame) {
let oldFrameActor = this._animations.get_child_at_index(this._frame);
if (oldFrameActor)
return GLib.SOURCE_CONTINUE;
}
+ _syncAnimationSize() {
+ if (!this._isLoaded)
+ return;
+
+ let [width, height] = this.actor.get_size();
+
+ for (let i = 0; i < this._animations.get_n_children(); ++i)
+ this._animations.get_child_at_index(i).set_size(width, height);
+ }
+
_animationsLoaded() {
this._isLoaded = this._animations.get_n_children() > 0;
+ this._syncAnimationSize();
+
if (this._isPlaying)
this.play();
}